import {produce} from 'immer';

/**
 * 搜索选项 三级关联选单，暂存数据
 * @author caohuayu@baijia.com
 * @date 2020-05-27
 */
const initialState = {
    // 业务线
    business: null,
    businessList: [],
    // 应用
    project: null,
    projectList: [],
    // 路径
    path: null,
    pathList: [],
};

/**
 * 三个页面分别保存，数据有三份
 * analysis 性能分析, rank 排行, userFeature 用户特征
 */
export default {
    state: {
        analysis: {
            ...initialState,
        },
        rank: {
            ...initialState
        },
        userFeature: {
            ...initialState
        }
    },

    action: {
        reset(payload) {
            return payload;
        },
        setInfo(payload) {
            return payload;
        }
    },

    reducer: {
        reset(state, action) {
            const {payload} = action;
            const nextState = produce(state, draft => {
                draft[payload] = {
                    ...initialState
                };
            });
            return nextState;
        },
        setInfo(state, action) {
            const {payload} = action;
            const nextState = produce(state, draft => {
                draft[payload.system] = {
                    ...payload.data
                };
            });
            return nextState;
        }
    }
};
